#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define flr(x,l,r) for (int x = l; x <= r; ++ x)
#define frl(x,r,l) for (int x = r; x >= l; -- x)
#define LL long long
#define szf sizeof
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector 
#define pb push_back
#define sz size

using namespace std;

const int N = 20, P = 1e9 + 7;

struct F {
    int s0, s1, s2;
}f[N][10][7][7];

int power7[N], power9[N];

int mod(LL x, int y) {
    return (x % y + y) % y;
}

void init() {
    flr (j, 0, 9) {
        if (j == 7) con;
        auto &v = f[1][j][j % 7][j % 7];
        v.s0 ++, v.s1 += j, v.s2 += j * j;
    }
    
    LL power = 10;
    for (int i = 2; i < N; ++ i, power *= 10)
        flr (j, 0, 9) {
            if (j == 7) con;
            flr (a, 0, 6)
                flr (b, 0, 6)
                    flr (k, 0, 9) {
                        if (k == 7) con;
                        auto &v1 = f[i][j][a][b], &v2 = f[i - 1][k][mod(a - j * power, 7)][mod(b - j, 7)];
                        v1.s0 = mod(v1.s0 + v2.s0, P);
                        v1.s1 = mod(v1.s1 + v2.s1 + j * (power % P) % P * v2.s0, P);
                        v1.s2 = mod(v1.s2 + 
                                    j * j * (power % P) % P * (power % P) % P * v2.s0 + 
                                    v2.s2 + 
                                    2 * j * power % P * v2.s1,
                                    P);
                    }
        }
        
    power7[0] = 1;
    flr (i, 1, N - 1) power7[i] = power7[i - 1] * 10 % 7;
    
    power9[0] = 1;
    flr (i, 1, N - 1) power9[i] = power9[i - 1] * 10ll % P;
}

F get(int i, int j, int a, int b) {
    int s0 = 0, s1 = 0, s2 = 0;
    flr (x, 0, 6)
        flr (y, 0, 6)
         if (x != a && y != b) {
             auto v = f[i][j][x][y];
             s0 = (s0 + v.s0) % P;
             s1 = (s1 + v.s1) % P;
             s2 = (s2 + v.s2) % P;
         }
         
    return {s0, s1, s2};
}

int dp(LL n) {
    if (!n) return 0;
    
    LL backup_n = n % P;
    vc<int> nums;
    while (n) nums.pb(n % 10), n /= 10;
    
    int res = 0;
    LL last_a = 0, last_b = 0;
    frl (i ,nums.sz() - 1, 0) {
        int x = nums[i];
        flr (j, 0, x - 1) {
            if (j == 7) con;
            int a = mod(-last_a * power7[i + 1], 7);
            int b = mod(-last_b, 7);
            auto v = get(i + 1, j, a, b);
            
            res = mod(
                res + 
                (last_a % P) * (last_a % P) % P * power9[i + 1] % P * power9[i + 1] % P * v.s0 % P + 
                v.s2 + 
                2 * last_a % P * power9[i + 1] % P * v.s1,
            P);
        }
        
        if (x == 7) bk;
        last_a = last_a * 10 + x;
        last_b += x;
        
        if (!i && last_a % 7 && last_b % 7) res = (res + backup_n * backup_n) % P;
    }
    
    return res;
}

int main() {
	int T;
	in(T);
	
	init();
	
	while (T -- ) {
	    LL l, r;
	    cin >> l >> r;
	    cout << mod(dp(r) - dp(l - 1),P);
	    pn;
	}
	
	return 0;
}